﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;

/// <summary>
/// Summary description for _Licence_type
/// </summary>
public class _Licence_type
{
	public _Licence_type()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public int _id { get; set; }
    public string _licence_type { get; set; }

    public static List<_Licence_type> SelectLicenceTypes()
    {
        _Licence_type item = new _Licence_type();
        List<_Licence_type> list = new List<_Licence_type>();

        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);

        string command = "SELECT * FROM LICENCE_TYPE";

        SqlCommand commandz = new SqlCommand(command, conn);

        try
        {
            conn.Open();

            using (SqlDataReader dr = commandz.ExecuteReader())
            {
                while (dr.Read())
                {
                    item._id = (int)dr[0];
                    item._licence_type = dr[1].ToString();
                    list.Add(item);
                }
                dr.Close();
            }
        }
        catch { System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Error in reading data!')</SCRIPT>"); }

        return list;
    }

    public static _Licence_type SelectLicType(string id)
    {
        _Licence_type LicType = new _Licence_type();

        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);

        string command = "SELECT * FROM Licence_type WHERE (id = @id)";

        SqlCommand commandz = new SqlCommand(command, conn);

        commandz.Parameters.Add(new SqlParameter("@id", System.Data.SqlDbType.Int));
        commandz.Parameters["@id"].Value = id;

        try
        {
            conn.Open();

            using (SqlDataReader dr = commandz.ExecuteReader())
            {
                while (dr.Read())
                {
                    LicType._id = (int)dr[0];
                    LicType._licence_type = dr[1].ToString();
                }
                dr.Close();
            }
        }
        catch { System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Error in reading data!')</SCRIPT>"); }

        return LicType;
    }
}